<?php

include "../librari/koneksi.php";
include "function.php";

$lowongan = 1;
$low = getLowongan($lowongan);
echo "Data Pelamar $low<br/>
<table><tr><td>No</td><td>Nama</td><td>Logika</td><td>Kecermatan</td><td>Kepribadian</td><td>Karakter</td></tr>";
$no = 1;
$pelamar = getPelamar($lowongan);
$pelamarid[][]="";
$id_pelamar = array();
$a=0;
while($data = mysql_fetch_array($pelamar)) {
    $pelamarid[$a][0]=getLogika($data[logika]);
    $pelamarid[$a][1]=getKecermatan($data[kecermatan]);
    $pelamarid[$a][2]=$data[kepribadian];
    $pelamarid[$a][3]=$data[karakter];
    $id_pelamar[$a] = $data[id_pelamar];
    echo "<tr><td>$no</td><td>".getNamaPelamar($data[id_pelamar])."</td><td>".$pelamarid[$a][0]."</td>
        <td>".$pelamarid[$a][1]."</td><td>".$pelamarid[$a][2]."</td><td>".$pelamarid[$a][3]."</td></tr>";
    $a++;
    $no++;
}
echo "</table>";

echo "<br/><br/>";

for($x = 0;$x<4;$x++) {
    if($x == 0) {
        $kat = "Logika";
        $kol = "vp_log";
    }
    elseif($x == 1) {
        $kat = "Kecermatan";
        $kol = "vp_kec";
    }
    elseif($x == 2) {
        $kat = "Kepribadian";
        $kol = "vp_kep";
    }
    else {
        $kat = "Karakter";
        $kol = "vp_kar";
    }

    echo "Perbandingan $kat";

    $log = 0;
    echo "<table border=1>
    <tr><th>$kat</th><th>Pelamar</th><th>Pelamar</th><th>Pelamar</th><th>Pelamar</th><th>Pelamar</th></tr>";
    for($log=0;$log<$a;$log++) {
        echo "<tr><td>pelamar</td>";
        for($log1=0;$log1<$a;$log1++) {
            echo "<td>".getPerbandingan($pelamarid[$log][$x],$pelamarid[$log1][$x])."</td>";
        }
        echo "</tr>";
    }
    $logic=array();
    echo "<tr><td>Jumlah</td>";
    for($log=0;$log<$a;$log++) {
        for($log1=0;$log1<$a;$log1++) {
            $logic[$log]= $logic[$log]+getPerbandingan($pelamarid[$log1][$x],$pelamarid[$log][$x]);
        }
        echo "<td>$logic[$log]</td>";
    }
    echo "</tr>";
    echo "</table>";

    echo "<br/><br/>Vektor Prioritas 1 $kat<table border=1>
            <tr><th>$kat</th><th>Pelamar</th><th>Pelamar</th><th>Pelamar</th><th>Pelamar</th><th>Pelamar</th>
            <th>Jml Baris 1</th><th>VP</th></tr>";
    $baris=array();
    $vp=array();
    for($l=0;$l<$a;$l++) {
        echo "<tr><td>Pelamar</td>";
        for($k=0;$k<$a;$k++) {
            echo "<td>".round(getPerbandingan($pelamarid[$log][$x],$pelamarid[$log1][$x])/$logic[$l],2)."</td>";
            $baris[$l]=$baris[$l]+round(getPerbandingan($pelamarid[$log][$x],$pelamarid[$log1][$x])/$logic[$l],2);
        }
        //jum pelamar = 5
        $vp[$l]=$baris[$l]/5;
        echo "<td>$baris[$l]</td><td>$id_pelamar[$l] : ".($vp[$l])."</td></tr>";
        $query = "UPDATE nilai_pelamar SET ".$kol." = $vp[$l] where id_pelamar = $id_pelamar[$l];";
        mysql_query($query) or die("Error : ".mysql_error());
    }
    echo "</table>";

    echo "<br/><br/>Hitung dari VP 1 $kat<table border=1>
            <tr><th>$kat</th><th>Pelamar</th><th>Pelamar</th><th>Pelamar</th><th>Pelamar</th><th>Pelamar</th>
            <th>Jml Baris 2</th>";
    $baris2=array();
    for($log=0;$log<$a;$log++) {
        echo "<tr><td>Pelamar</td>";
        for($log1=0;$log1<$a;$log1++) {
            echo "<td>".(getPerbandingan($pelamarid[$log][$x],$pelamarid[$log1][$x])*($baris[$log1]/5))."</td>";
            $baris2[$log]=$baris2[$log]+(getPerbandingan($pelamarid[$log][$x],$pelamarid[$log1][$x])*($baris[$log1]/5));
        }
        echo "<td>$baris2[$log]</td></tr>";
    }
    echo "</table>";
    $lamda = 0;
    echo "<br/><br/>Hasil berikutnya $kat<table border=1>";
    for($log=0;$log<$a;$log++) {
        echo "<tr><td>".round($baris2[$log]/$vp[$log])."</td></tr>";
        $lamda = $lamda+round($baris2[$log]/$vp[$log]);
    }
    echo "</table>";

//jml pelamar = 5
    $lamdamax = $lamda/5;
    echo "Lamda Maks $kat : $lamdamax<br/>";
    $ci = ($lamdamax-5)/(5-1);
    echo "<br/>CI $kat : $ci => ";

    if($ci<0.1) {
        echo "true<br/>";
    }
    else {
        echo "false<br/>";
    }

    echo "<br/><br/>";

}

echo "<h3>Perbandingan antar Pelamar</h3>";
$vplow = getLowonganVP($lowongan);
$logika = 0.00; $kec=0.00; $kep=0.00; $kar=0.00;
echo "<br/><br/>Nilai VP Lowongan<table border=1>";
$vplowongan=array();
while($data = mysql_fetch_array($vplow)){
    $vplowongan[0] = $data[logika];
    $vplowongan[1] = $data[kecermatan];
    $vplowongan[2] = $data[kepribadian];
    $vplowongan[3] = $data[karakter];
    echo "<tr><td>Logika</td><td>$vplowongan[0]</td><td>Kecermatan</td><td>$vplowongan[1]</td><td>Kepribadian</td>
            <td>$vplowongan[2]</td><td>Karakter</td><td>$vplowongan[3]</td></tr>";
}
echo "</table>";
echo"<br/><br/>VP Pelamar<table border=1>";
$vppelamar = getPelamarVP($lowongan);
$vppel[][]="";
$a=0;
$no = 1;
$idpel;
while($data = mysql_fetch_array($vppelamar)){
    $vppel[$a][0]=$data[vp_log];
    $vppel[$a][1]=$data[vp_kec];
    $vppel[$a][2]=$data[vp_kep];
    $vppel[$a][3]=$data[vp_kar];
    $idpel[$a]=$data[id_pelamar];
    echo "<tr><td>$no</td><td>".getNamaPelamar($idpel[$a])."</td><td>".$vppel[$a][0]."</td>
        <td>".$vppel[$a][1]."</td><td>".$vppel[$a][2]."</td><td>".$vppel[$a][3]."</td></tr>";
    $a++;
    $no++;
}
echo "</table>";

echo "<br/><br/>VP menyeluruh<table border=1>
            <tr><th>Pelamar</th><th>Logika</th><th>Kecermatan</th><th>Kepribadian</th><th>Karakter</th>
            <th>VP menyeluruh</th>";
    $vpall=array();
    for($log=0;$log<$a;$log++) {
        $jum = 0;
        echo "<tr><td>".getNamaPelamar($idpel[$log])."</td>";
        for($log1=0;$log1<4;$log1++) {
            echo "<td>".($vppel[$log][$log1]*$vplowongan[$log1])."</td>";
            $jum=$jum+($vppel[$log][$log1]*$vplowongan[$log1]);
        }
        echo "<td>".round($jum,2)."</td></tr>";
        $query = "UPDATE nilai_pelamar SET vp_all = $jum where id_pelamar = $idpel[$log];";
        mysql_query($query) or die("Error : ".mysql_error());
    }
echo "</table>";
$winner = getWinner($lowongan);
echo "<br/><br/><h3>And The Winner for $low is <b>".getNamaPelamar($winner)."</b></h3>";

?>
